<template>
    <div class="app-container">
        <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column label="ID">
        <template slot-scope="scope">
            <span>{{ scope.row._id }}</span>
        </template>
        </el-table-column>
        <el-table-column
        label="姓名"
        width="180">
        <template slot-scope="scope">
            <span>{{ scope.row.name }}</span>
        </template>
        </el-table-column>
        <el-table-column
        label="分数"
        width="180">
        <template slot-scope="scope">
            <span>{{ scope.row.score }}</span>
        </template>
        </el-table-column>
        <el-table-column
        label="性别"
        width="180">
        <template slot-scope="scope">
            <el-tag v-if="scope.row.gender" size="medium" :type="scope.row.gender==1?'':'danger'">
                {{ scope.row.gender==1?'男':'女' }}
            </el-tag>
        </template>
        </el-table-column>
        <el-table-column label="操作">
        <template slot-scope="scope">
            <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
        </el-table-column>
    </el-table>
    </div>
  
</template>

<script>
  import {stuList} from '@/api/stu'
  export default {
    data() {
      return {
        tableData: [
            // {
            //     _id: 'asdfasdfad',
            //     name: '王小虎',
            //     score:100,
            //     gender:1
            // }
        ]
      }
    },
    created () {
        stuList().then(res=>{
            console.log(res);
            this.tableData = res.data.data
        })
    },
    methods: {
      handleEdit(index, row) {
        this.$router.push({
            path:'/stu/edit',
            query:row
        })
      },
      handleDelete(index, row) {
        console.log(index, row);
      }
    }
  }
</script>